package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.FixedAssetsStatistics;
import com.amsp.oa.oademo.service.FixedAssetsStatisticsService;
import com.amsp.oa.oademo.vo.FixedAssetsStatisticsVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/fixed-assets-statistics")
@Api(tags = "固定资产月度统计表管理")
@CrossOrigin
public class FixedAssetsStatisticsController {

    @Autowired
    private FixedAssetsStatisticsService statisticsService;

    @PostMapping("/save")
    @ApiOperation("保存固定资产月度统计表")
    public ResponseEntity<Boolean> save(@RequestBody FixedAssetsStatisticsVO statisticsVO) {
        return ResponseEntity.ok(statisticsService.saveStatistics(statisticsVO));
    }

    @GetMapping("/list")
    @ApiOperation("获取固定资产月度统计表列表")
    public ResponseEntity<IPage<FixedAssetsStatistics>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String monthDate) {
        return ResponseEntity.ok(statisticsService.getPage(current, size, monthDate));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取固定资产月度统计表详情")
    public ResponseEntity<FixedAssetsStatisticsVO> getById(@PathVariable Long id) {
        return ResponseEntity.ok(statisticsService.getDetailById(id));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除固定资产月度统计表")
    public ResponseEntity<Boolean> delete(@PathVariable Long id) {
        return ResponseEntity.ok(statisticsService.deleteWithDetails(id));
    }
}